home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c
- Subject: Re: The size of a file
- Date: 30 Jan 1996 18:44:43 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan30134443@g7240065.bridge.bst.bls.com>
- References: <4ebc03$4gv@gate.compart.fi> <59.28250.5782@windmill.com>
- <4elf3v$s5o@noc.tor.hookup.net>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: Richard Steadman's message of 30 Jan 1996 15:56:47 GMT
-
- In article <4elf3v$s5o@noc.tor.hookup.net> Richard Steadman <rsteadma@mmltd.com> writes:
- : charlie.brown@windmill.com (Charlie Brown) wrote:
- :> [* Original attribution lost *]
- :>> This is driving me nuts. I can't find a simple way to get the size of a
- :>> disk file. This must be possible using the standard C library, but I
- :>> haven't figured out how!
- :>
- :> This works with MSC, Borland may have a different name
- :> for _dos_findfirst().
- :>
- :> #include <dos.h>
- :> long fsize(filespec)
- :> char *filespec;
- :> {
- :> struct find_t fileinfo;
- :>
- :> if(0 == _dos_findfirst(filespec,0,&fileinfo))
- :> return fileinfo.size;
- :> else
- :> return 0L;
- :> }
-
- But this doesn't answer his question. He wanted to use the standard C library
- and _dos_findfirst() is not in the ANSI spec.
-
- The usual method is to fopen() a file in binary mode and fseek() to the
- end and the use the result of ftell() as the file size. Though the standard
- allows this not to work for some binary streams (see fseek() description) it
- practise if the stream is attached to a file then it should work.
-
- : But there's no way to get the file size if its length is greater
- : than will fit in a long int?
-
- The minimum size for long int is 4 bytes - this is only a minimum it can
- be bigger.
- Maximum value for 4 byte long is 2147483647 which is 2 gigabytes, in practise
- not many files will break this limit. In fact your operating system may not
- be able to deal with files bigger than this.
-
- Regards
-
- -A.
-
-
- --
- | A.Champion |
-